<template>
	<view class="chatInfo">
		<view class="chatName">
			<view>群聊名字：</view>
			<input v-model="group.name" />
		</view>
		<view class="chatRemark">
			<view>群公告：</view>
			<input v-model="group.remark" />
		</view>

		<button @click="add">添加</button>
		<button>取消</button>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		reactive,
		ref
	} from "vue";

	// 获取token
	const token = uni.getStorageSync('token');

	const group = reactive({
		name: "",
		remark: ""
	})

	const ID = ref(0)

	// 创建群聊
	const add = async () => {
		console.log("添加群聊");
		await uni.request({
			url: "http://192.168.1.200:8080/groupInfo/addGroupChat",
			method: 'POST',
			header: {
				'Content-Type': 'application/json',
				'token': token,
			},
			data: {
				// 群聊名
				groupName: group.name,
				// 群公告
				groupRemark: group.remark,
				// 加群方式（0，1，2）
				groupStatus: 0,
				// 加强方式
				groupLockPwd: null,
				// 创建人ID
				selfId: ID.value
			}

		})

		// 跳转到首页
		uni.switchTab({
			url: "/pages/index/index"
		})
	}


	onLoad(async () => {
		const own = await uni.request({
			url: "http://192.168.1.200:8080/user/userInfo",
			method: 'POST',
			header: {
				'Content-Type': 'application/json',
				'token': token,
			}
		})
		// console.log(own);

		ID.value = own.data.data.id

	})
</script>

<style lang="scss">
	.chatInfo {

		input {
			background-color: skyblue;
			width: 80%;
			margin: 10rpx auto;
			padding-left: 40rpx;

		}
	}
</style>